<template>
  <div>
    <el-input size="mini" placeholder="搜索企业" style="width: 40%" v-model="search" @keyup.enter.native="searchCompany"> </el-input>
    <div class="docs" v-for="(item,key,index) in docs" :key="item.id" >
      <div class="img">
        <img src="../../assets/img/word_logo.png" alt="">
      </div>
      <div class="content">
        <h5 style="float: left;width: 300px">{{item.title}}</h5>
        <p style="float: left;line-height: 10px;margin-left: 100px">{{map[item.cid].companyName}}</p>
        <el-button  @click="deleteDoc(item.id)" style="margin-top: 6px;float: right" size="mini" ><i class="el-icon-delete"></i></el-button>
        <a :href="url"><el-button @click="downDoc(item.id)" style="margin-top: 6px;float: right;margin-right: 30px" size="mini"><i class="el-icon-download"></i></el-button></a>
        <h5 style="float: right;margin-right: 30px">{{item.createTime|formatDate}}</h5>
      </div>
    </div>
  </div>

</template>

<script>
import {getCompanyPractice,delDoc} from "../../network/admin"
import {baseUrl} from "../../network/baseUrl";

export default {
  name:'practice',
  data(){
    return{
      search:'',
      baseUrl:baseUrl(),
      dialogVisible:false,
      url:'',
      upData:{
        title:''
      },
      map:[],
      docs:[],
      fileList:[],
    }
  },
  created() {
    this.getData()
  },
  methods:{
    searchCompany(){     //搜索
      getCompanyPractice(this.search)
      .then(res=>{
        this.docs=res.data.extend.practiceMap
        this.map=res.data.extend.companyMap
      })
    },
    getData(){
      getCompanyPractice()
          .then(res=>{
            console.log(res)
            // this.docs=res.data.extend.page.records
            this.docs=res.data.extend.practiceMap
            this.map=res.data.extend.companyMap
            console.log(this.docs,1)
          })
    },
    deleteDoc(id){
      delDoc(id)
          .then(res=>{
            console.log(res)
            this.$message.success("删除成功!")
            this.getData()
          })
    },
    upDoc(){
      this.dialogVisible=true
      this.upData.title=''
      this.fileList=[]
    },
    upDocSubmit(){
      this.$refs.upload.submit()
    },
    downDoc(id){
      this.url=baseUrl()+'/admin/downloadPractice/'+id
    },
    success(res){
      if(!this.upData.title){
        this.$message.warning("请填写标题~")
      }else {
        if(res.code===100){
          this.$message.success("提交成功!")
          this.dialogVisible=false
          this.getData()
        }else {
          this.$message.warning(res.msg)
        }
      }
    },
    fail(){
      this.$message.warning("上传失败!")
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
    },
  }

}
</script>

<style scoped>
.docs h5{
  padding: 0;
  margin: 0;
}
.docs{
  cursor: pointer;
  width: 100%;
  height: 40px;
  transition: all .1s;
  border-bottom: 1px solid gainsboro;
}
.docs:hover{
  background-color: gainsboro;
}
.docs .img{
  float: left;
  height: 100%;
  width: 60px;
}
.docs img{
  height: 100%;
  width: 100%;
}
.content{
  float: left;
  height: 100%;
  width: 80%;
}
.content h5{
  line-height: 40px;
}
</style>
